﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace Ivy.Common.Framework.Configuration
{
    /// <summary>
    /// This class will represent the main config section instance, it should be inherited from 'ConfigurationSection' base class
    /// </summary>
    public sealed class FrameworkIvyConfigSection : ConfigurationSection
    {
        #region Variables & Constants
        /// <summary>
        /// Constant string to uniquely identify the config section name (XML node name) in the ????.config file
        /// </summary>
        const string _FrameworkIvyConfigSection = "FrameworkIvyConfigSection";

        /// <summary>
        /// Constant string to uniquely identify the child XML node inside the config section
        /// </summary>
        const string _SmtpMailServers = "SmtpMailServers";
        #endregion Variables & Constants

        #region Constructor & Destructor
        #endregion Constructor & Destructor

        #region Public Properties
        /// <summary>
        /// All the immediate child XML nodes that should be present inside the main config section
        /// Example <FrameworkIvyConfigSection> is the main config section
        /// Example     <SmtpMailServers>       is the immediate child noide
        /// Example         <...../>
        /// Example         <...../>
        /// Example     </SmtpMailServers>
        /// Example </FrameworkIvyConfigSection>
        /// In the above example it is <SmtpMailServers> which can have more than one child elements
        /// For any new elements directly under the main config section we need to mane a new property similar to this one.
        /// </summary>
        [System.Configuration.ConfigurationProperty(_SmtpMailServers)]
        public SmtpMailServers SmtpMailServers
        {
            get
            {
                //object _tempObject = this[_SmtpMailServers];
                //return _tempObject as SmtpMailServers;
                return ((SmtpMailServers)(base[_SmtpMailServers])); 
            }
        }
        #endregion Public Properties

        #region Public Methods
        /// <summary>
        /// There should be a public method which will return an instance of the config section class
        /// in this case it is 'FrameworkIvyConfigSection'
        /// </summary>
        /// <returns></returns>
        public static FrameworkIvyConfigSection GetConfig()
        {
            return (FrameworkIvyConfigSection)System.Configuration.ConfigurationManager.GetSection(_FrameworkIvyConfigSection) ?? new FrameworkIvyConfigSection();
        }
        #endregion Public Methods

        #region Events
        #endregion Events

        #region Private Methods
        #endregion Private Methods
    }
}
